USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[UsersLogs-Insert]    Script Date: [[20120714223944]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223944]]
-- Description:	Insert record into table [dbo].[UsersLogs]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[UsersLogs-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[UsersLogs-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[UsersLogs-Insert]
	/*@RowNumber int =Null OUTPUT , 
	@ID uniqueidentifier =Null  , 
	@User_ID uniqueidentifier =Null  , 
	@Date datetime =Null  , 
	@Table_ID uniqueidentifier =Null  , 
	@Event_ID uniqueidentifier =Null  , 
	@Item_ID uniqueidentifier =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[UsersLogs](/*[ID], [User_ID], [Date], [Table_ID], [Event_ID], [Item_ID]*/)
	VALUES     (/*@ID, @User_ID, @Date, @Table_ID, @Event_ID, @Item_ID*/)

	/*SELECT @RowNumber = [RowNumber]
    FROM [dbo].[UsersLogs]
    WHERE  ( [ID] =@ID )
	AND  ( [User_ID] =@User_ID )
	AND  ( [Date] =@Date )
	AND  ( [Table_ID] =@Table_ID )
	AND  ( [Event_ID] =@Event_ID )
	AND  ( [Item_ID] =@Item_ID )*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[UsersLogs-update]    Script Date: [[20120714223944]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223944]]
-- Description:	Update record in table [dbo].[UsersLogs]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[UsersLogs-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[UsersLogs-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[UsersLogs-update]
	/*@RowNumber int =Null OUTPUT , 
	@ID uniqueidentifier =Null  , 
	@User_ID uniqueidentifier =Null  , 
	@Date datetime =Null  , 
	@Table_ID uniqueidentifier =Null  , 
	@Event_ID uniqueidentifier =Null  , 
	@Item_ID uniqueidentifier =Null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/**/
		Update [dbo].[UsersLogs] SET 
		/*[ID] =@ID, 
		[User_ID] =@User_ID, 
		[Date] =@Date, 
		[Table_ID] =@Table_ID, 
		[Event_ID] =@Event_ID, 
		[Item_ID] =@Item_ID*/
		/*WHERE ([ID] = @ID)*/
	/**/

	/*SELECT @RowNumber = [RowNumber]
    FROM [dbo].[UsersLogs]
	WHERE ([ID] = @ID)*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[UsersLogs-Insert-Update]    Script Date: [[20120714223944]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223944]]
-- Description:	Insert OR Update record into table [dbo].[UsersLogs]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[UsersLogs-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[UsersLogs-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[UsersLogs-Insert-Update]
	/*@RowNumber int =Null OUTPUT , 
	@ID uniqueidentifier =Null  , 
	@User_ID uniqueidentifier =Null  , 
	@Date datetime =Null  , 
	@Table_ID uniqueidentifier =Null  , 
	@Event_ID uniqueidentifier =Null  , 
	@Item_ID uniqueidentifier =Null  , 
	@Inserted bit OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[UsersLogs] 
					/*WHERE ([ID] = @ID)*/)
	BEGIN
		
		INSERT  INTO [dbo].[UsersLogs](/*[ID], [User_ID], [Date], [Table_ID], [Event_ID], [Item_ID]*/)
		VALUES     (/*@ID, @User_ID, @Date, @Table_ID, @Event_ID, @Item_ID*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/**/
			Update [dbo].[UsersLogs] SET 
			/*[ID] =@ID, 
			[User_ID] =@User_ID, 
			[Date] =@Date, 
			[Table_ID] =@Table_ID, 
			[Event_ID] =@Event_ID, 
			[Item_ID] =@Item_ID*/
			/*WHERE ([ID] = @ID)*/
		/**/
		
		SET /*@*/Inserted=0
	END

	/*SELECT @RowNumber = [RowNumber]
    FROM [dbo].[UsersLogs]
	WHERE ([ID] = @ID)*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[UsersLogs-Delete]    Script Date: [[20120714223944]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223944]]
-- Description:	delete records from table [dbo].[UsersLogs] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[UsersLogs-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[UsersLogs-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[UsersLogs-Delete]
	/*@RowNumber int =null  , 
	@ID uniqueidentifier =null  , 
	@User_ID uniqueidentifier =null  , 
	@Date datetime =null  , 
	@Table_ID uniqueidentifier =null  , 
	@Event_ID uniqueidentifier =null  , 
	@Item_ID uniqueidentifier =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[UsersLogs]
	WHERE /*( [RowNumber] = ISNULL(@RowNumber, [RowNumber]) )
	AND ( [ID] = ISNULL(@ID, [ID]) )
	AND ( [User_ID] = ISNULL(@User_ID, [User_ID]) )
	AND ( [Date] = ISNULL(@Date, [Date]) )
	AND ( [Table_ID] = ISNULL(@Table_ID, [Table_ID]) )
	AND ( [Event_ID] = ISNULL(@Event_ID, [Event_ID]) )
	AND ( [Item_ID] = ISNULL(@Item_ID, [Item_ID]) )*/
END
GO
-- =============================================
USE [StoresManagement]
/****** Object:  StoredProcedure [dbo].[UsersLogs-Select]    Script Date: [[20120714223944]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120714223944]]
-- Description:	select records from table [dbo].[UsersLogs] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[UsersLogs-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[UsersLogs-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[UsersLogs-Select]
	/*@RowNumber int =null  , 
	@ID uniqueidentifier =null  , 
	@User_ID uniqueidentifier =null  , 
	@Date datetime =null  , 
	@Table_ID uniqueidentifier =null  , 
	@Event_ID uniqueidentifier =null  , 
	@Item_ID uniqueidentifier =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[UsersLogs]
	WHERE /*( [RowNumber] = ISNULL(@RowNumber, [RowNumber]) )
	AND ( [ID] = ISNULL(@ID, [ID]) )
	AND ( [User_ID] = ISNULL(@User_ID, [User_ID]) )
	AND ( [Date] = ISNULL(@Date, [Date]) )
	AND ( [Table_ID] = ISNULL(@Table_ID, [Table_ID]) )
	AND ( [Event_ID] = ISNULL(@Event_ID, [Event_ID]) )
	AND ( [Item_ID] = ISNULL(@Item_ID, [Item_ID]) )*/
END
GO
-- =============================================
